package com.example.user.service.impl;

import com.example.common.util.JwtUtils;
import com.example.shared.entity.User;
import com.example.shared.repository.UserRepository;
import com.example.user.payload.LoginPayload;
import com.example.user.service.AuthService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

@Service
public class AuthServiceImpl implements AuthService {
    @Autowired
    private UserRepository userRepository;
    @Value("${jwt.key}")
    private String key;
    @Value("${jwt.expires-in}")
    private long expiresIn;

    @Override
    public String login(LoginPayload loginPayload) {
        User user = userRepository.findByName(loginPayload.getName());
        return JwtUtils.generateToken(key, user.getName(), expiresIn);
    }

    @Override
    public void logout() {

    }
}
